/**
 * @(#) TotalIncomProxy.as
 *
 * @date		2009. 04. 23.
 * @version		1.0
 * @author		Jo,Chang Hun
 * @description	 연말정산  - Proxy
 * 				특별공제 보험료 입력 관리 
 */
package com.skt.common_hr.yearadjustment.model
{
	
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.skt.common_hr.yearadjustment.YearAdjustmentFacade;
	import com.skt.common_hr.yearadjustment.model.vo.ComboFamilyVO;
	
	import mx.collections.ArrayCollection;
	import mx.managers.CursorManager;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	

	public class EduComboProxy extends CommonProxy
	{
		public static const NAME:String = "EduComboProxy";
		public var msgStr:String;
		public var comboGubun:ArrayCollection = new ArrayCollection();
		

		/**
		 * 생성자
		 * 
		 * @param
		 * @return void
		 */
		public function EduComboProxy(data:Object=null)
		{
			super(NAME, data);
		}
		
		
		/**
		 * data load를 수행
		 * 		- DataLoader 를 생성하고 Import Parameter 객체를 생성, RFC를 호출
		 * 
		 * @param pernr 사번
		 * @return void
		 */
		public function comboload():void
		{
			//CursorManager.setBusyCursor();
			//var loader:IDataLoader = DataLoaderFactory.getDataLoader("Z_HR_0096");
			
			var param:Object = new Object();
			param["I_YEAGBN"] = "02"; 	//비용구분 ( 02:교육비용, 06:가족관계 )
			loadData("Z_HR_0096_NEW", param, comboResult, comboFault); 
		}
		

		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Event Listeners
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 정상적으로 리턴된 결과를 처리
		 * 
		 * @param
		 * @return void
		 */
		public function comboResult(event:ResultEvent):void
		{
			if(retCode==0) {  
				trace( "suss to save LOAD_COMBO_FAMILY_COMPLETE");
				comboGubun = parseComboGubun(event.result.ITAB);
				facade.sendNotification(YearAdjustmentFacade.LOAD_EDUGUBUNCOMBO_COMPLETE, this);
			}
			else {
				trace( "failed to load LOAD_COMBO_FAMILY_FAILED: (" +event.result["RETCODE"] + ") "+event.result["RETTEXT"]);
				msgStr = event.result["RETTEXT"];
				facade.sendNotification(YearAdjustmentFacade.LOAD_EDUGUBUNCOMBO_FAILED, this);
			}
		}
		
		//관계 콤보박스 조회 실패
		private function comboFault(event:FaultEvent):void
		{
			trace("Fault message in save: " + event.fault.faultString);
			msgStr = event.fault.faultString;
			facade.sendNotification(YearAdjustmentFacade.LOAD_EDUGUBUNCOMBO_FAILED, this);
		}
		
		
		///////////////////////////////////////////////////////////////////////////////////////////////////
		//
		//	Data Parsing functions
		//
		///////////////////////////////////////////////////////////////////////////////////////////////////
		/**
		 * 서버에서 전달된 result 객체를 분석하여 Value Object를 생성
		 * 
		 * @param
		 * @return 연말정산  MainList Value Object
		 */
		/**
		 * 개인정보
		 * 
		 * @param
		 * @return 특별공제 보험료 Value Object
		 */
		private function parseComboGubun(arr:ArrayCollection):ArrayCollection
		{
			var returnArr:ArrayCollection = new ArrayCollection();
			for each(var reg:Object in arr){
				var vo:ComboFamilyVO = new ComboFamilyVO();
				
				vo.CODE	= reg["YEASUB"];
				vo.TEXT	= reg["YEASTX"];
				
				returnArr.addItem(vo);
			}
			returnArr.addItemAt({CODE:'',TEXT:'종류선택'}, 0);
			return returnArr;
		}
		
	}
}